package com.miaow.common;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.cloud.stream.annotation.StreamListener;
import org.springframework.cloud.stream.messaging.Sink;
import org.springframework.cloud.stream.messaging.Source;
import org.springframework.messaging.MessageChannel;
import org.springframework.messaging.support.MessageBuilder;

/**
 * @author HWZ
 * @date 2023年12月20日 17:15
 * @description
 */
@EnableBinding(Sink.class)
//@EnableBinding(Source.class)
public class MessageProcessor {
    private final MessageChannel output;

    @Autowired
    public MessageProcessor(Source source) {
        this.output = source.output();
    }

    @StreamListener(Sink.INPUT)
    public void processMessage(String message) {
        // 处理输入消息
        System.out.println("Received message: " + message);

        // 处理完后可以发送输出消息
         output.send(MessageBuilder.withPayload("Output message").build());
    }
}
